<%@page import="entity.Banji_PageBean"%>
<%@page import="entity.PageBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="entity.Banji"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>banji_page_list</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
		<%-- ${list} --%>
	<form action="<%=request.getContextPath()%>/banji?method=search" method="post">
		名字：<input type="text" name="searchName"/>
		<input type="submit" value="搜索"/>
	</form>
	<a href="<%=request.getContextPath()%>/banji_insert.jsp" class="btn btn-success">添加</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名称</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<%
			Banji_PageBean pageBean = (Banji_PageBean)request.getAttribute("pageBean");
			for (Banji banji : pageBean.getList()) {
		%>
				<tr>
					<td><%=banji.getId()%></td>
					<td><%=banji.getName()%></td>
					<td><a href="javascript:void(0)" onclick="deleteById(<%=banji.getId()%>)" class="btn btn-danger">删除</a></td>
					<td><a href="<%=request.getContextPath()%>/banji?method=toUpdate&id=<%=banji.getId()%>" class="btn btn-warning">修改</a></td>
				</tr>
		<%
			}
		%>
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	  <%--上一页 --%>
		<% 
			if(pageBean.getPageNo() == 1){ 
		%>
			<li class ="disabled">
		   		<a aria-label="Previous">
	        		<span aria-hidden="true">&laquo;</span>
	      		</a>
	      	</li>
		<%
	      	} else {
	    %>
		
		<li>
			 <a href="<%=request.getContextPath()%>/banji?method=pageList&pageNo=<%=pageBean.getPageNo()-1%>" aria-label="Previous">
	        <span aria-hidden="true" >&laquo;</span>
	      </a>
		</li>


		<%
			}
		%>
<%--上一页结束--%>
	
		<%
		    for (int i = 1; i <= pageBean.getTotalPage(); i++) {
				if (pageBean.getPageNo() == i) {
		%>
					<li class="active"><a href="#"><%=i%></a></li>
		<%
				} else {
		%>
					<li><a href="<%=request.getContextPath()%>/banji?method=pageList&pageNo=<%=i%>"><%=i%></a></li>
		<%
				}
			}
	    %>
	   <%--下一页 --%>
	   	<% 
			if(pageBean.getPageNo() == pageBean.getTotalPage()){ 
		%>
			<li class ="disabled">
		   		<a aria-label="Next">
	        		<span aria-hidden="true">&raquo;</span>
	      		</a>
	      	</li>
		<%
	      	} else {
	    %>
		
		<li>
			 <a href="<%=request.getContextPath()%>/banji?method=pageList&pageNo=<%=pageBean.getPageNo()+1%>" aria-label="Next">
	        <span aria-hidden="true" >&raquo;</span>
	      </a>
		</li>

		<%
			}
		%>
  		<%--下一页结束 --%>
	  </ul>
	</nav>
	
	<script type="text/javascript">
		function deleteById(id) {
			var isDel = confirm("您确认要删除么？");
			if (isDel) {
				location.href = "/ST_JavaEE/banji?method=deleteById&id=" + id;
			}
		}
	</script>
	
</body>
</html>